home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / recent / create.lha / CreateIndex2.isrx < prev   
Text File  |  1998-06-14  |  6KB  |  228 lines

  1. /* ImageStudio ARexx script **************************************/
  2. /* V1.0 2 Nov 97 by James Perrin */
  3. /* V2.0 19 Nov 97 added ability to update an index if new images */
  4. /*      have been added to the directory */
  5. /* V2.1 24 May 98 added skipping of files unable to load eg progressive jpegs */
  6. /* V2.1D 25 May 98 added thumbnail dimension gernation, split development into 
  7. two scripts */
  8.  
  9. /* Allow commands to return results */
  10. options results
  11.  
  12. /* On error, goto ERROR:. Comment out this line if you wish to */
  13. /* perform your own error checking. */
  14.  
  15. signal on error
  16.  
  17. /* BEGIN PROGRAM *************************************************/
  18.  
  19. /* PROGRAM CONSTANTS - change these values to suit */
  20.  
  21. HTMLFile='Index.html'        /* What to call the html file, Oh Yes */
  22. SquareSize=100                    /* Size of square into which to fit pic */
  23. TNFormat='PNG'                    /* Thumbnail file format */
  24. TNExten='png'                        /* Thumnail file extension */
  25. TNPrefix='TN'                                    /* Thumbnail prefix */
  26. TableColumns=5                    /* No. of pics per row */
  27. TableBorder=1                        /* Size of table borders, in pixels */
  28.  
  29. FilePattern='~('||HTMLFile||'|'||TN||'#?)' /* only change if you understand arexx */
  30.  
  31. /* set program variables */
  32. nofile=0    /* flag that image can't be loaded */
  33.  
  34. /* get them files */
  35.  
  36. REQUEST_MULTIFILE TITLE '"Choose source files..."' PATTERN FilePattern STEM srcfiles.
  37.  
  38. /* Open html file and write basic info */
  39.  
  40. FILE_SPLIT FILE '"'srcfiles.files.0'"' STEM getpath.
  41. FILE_JOIN PATHPART '"'getpath.pathpart'"' FILEPART HTMLFile VAR WriteFile
  42.  
  43. if open('OutFile',WriteFile,'w') then
  44. do
  45.     call writeln('OutFile', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">')
  46.     call writeln('OutFile', '<HTML>')
  47.     call writeln('OutFile', '<HEAD>')
  48.     call writeln('OutFile', '<TITLE>Index of Directory '||getpath.pathpart||'</TITLE>')
  49.   call writeln('OutFile', '</HEAD>')
  50.     call writeln('OutFile', '<BODY>')
  51.     call writeln('OutFile', '<TABLE WIDTH="100%" BORDER='TableBorder'>')
  52.  
  53.     ColumnCount=1
  54.  
  55.     /* Process  each file */
  56.     do l = 0 to (srcfiles.files.count - 1)
  57.  
  58.         /* Create the destination file name */
  59.         FILE_SPLIT FILE '"'srcfiles.files.l'"' STEM filesplit.
  60.  
  61.         filename=left(filesplit.filepart,index(filesplit.filepart,'.')-1)
  62.  
  63.         FILE_JOIN PATHPART '"'filesplit.pathpart'"',
  64.         FILEPART '"'TNPrefix||filename'.'TNExten'"' VAR 'destfile'
  65.  
  66.  
  67.         /* if thumb nail not yet generated make one */
  68.         if exists(destfile) ~=1 then
  69.         do
  70.             /* Open the file, do our own error check */
  71.             signal off error
  72.                  
  73.             OPEN FILE '"'srcfiles.files.l'"' FORCE
  74.         
  75.             if (rc~=0) then
  76.             do
  77.                 /* deal with error */
  78.                 nofile=1
  79.                 signal on error
  80.                     
  81.             end    
  82.             else
  83.             do
  84.                 signal on error
  85.  
  86.                 /* Get and set size and depth info */
  87.                 IMAGEINFO_GET STEM ImageInfo.
  88.                 XPSize = SquareSize / ImageInfo.width
  89.                 YPSize = SquareSize / ImageInfo.height
  90.                 ImageDepth = ImageInfo.depth
  91.  
  92.                 /* 8-bit colors max */
  93.                 if ImageDepth>8 then
  94.                     ImageDepth=8
  95.  
  96.                 NumCol=1
  97.  
  98.                 do n=1 to ImageDepth
  99.                     NumCol=NumCol*2
  100.                 end
  101.  
  102.                 /* Fit image into square SquareSize X SquareSize */
  103.                 if (XPSize < YPSize) then
  104.                     PSize = (XPSize * 100) + 0.5
  105.                 else
  106.                     PSize = (YPSize * 100) + 0.5
  107.  
  108.                 PSize=trunc(PSize,0) /* number must be integer */
  109.     
  110.                 /* Rescale image , colour convertion neccessary for colour averaging */
  111.                 COLOURS SIXTEENMILLION
  112.                 SCALE  PSize PSize PERCENT METHOD "AVERAGE"
  113.                 COLOURS NUMCOLOURS NumCol
  114.  
  115.                 /* Save file */
  116.                 SAVE FILE '"'destfile'"' FORMAT TNFormat ARGS '"INTERLACE=ADAM7"' 
  117.                 
  118.                 /* get new dimensions */
  119.                 IMAGEINFO_GET STEM ImageInfo.
  120.  
  121.             end
  122.  
  123.         end    
  124.         else    /* load TN to get dimensions */
  125.         do
  126.             OPEN FILE '"'destfile'"' FORCE
  127.             
  128.             IMAGEINFO_GET STEM ImageInfo.            
  129.         end
  130.         
  131.         /* <<<<<<<< Write HTML for ThumbNail >>>>>>>>>*/
  132.         if ColumnCount=1 then
  133.             call writeln('OutFile','<TR>')
  134.  
  135.         if(~nofile) then /* TN exists */
  136.             call writeln('OutFile','<TD><A HREF="'filesplit.filepart'">'||,
  137. '<IMG SRC="'TNPrefix||filename'.'TNExten'" ALT="'filesplit.filepart'"'||,
  138. 'WIDTH="'ImageInfo.width'" HEIGHT="'ImageInfo.height'"></A>')
  139.         else    /* unable to create TN */
  140.         do
  141.             call writeln('OutFile','<TD><A HREF="'filesplit.filepart'">'||,
  142. filesplit.filepart'"</A>')
  143.             nofile=0
  144.         end
  145.             
  146.         ColumnCount=ColumnCount+1
  147.  
  148.         if ColumnCount > 5 then
  149.         do
  150.             call writeln('OutFile','</TR>')
  151.             ColumnCount=1
  152.         end
  153.  
  154.     end /* file loop */
  155.  
  156.     /* Finish writing html and close file */
  157.     if ColumnCount>1 then
  158.         call writeln('OutFile','</TR>')
  159.  
  160.     call writeln('OutFile', '</TABLE>')
  161.     call writeln('OutFile', '</BODY>')
  162.     call writeln('OutFile', '</HTML>')
  163.     call close('OutFile')
  164.  
  165. end /* if outfile */
  166.  
  167. /* END PROGRAM ***************************************************/
  168.  
  169. exit
  170.  
  171. /* On ERROR */
  172.  
  173. ERROR:
  174.  
  175. /* If we get here, either an error occurred with the command's */
  176. /* execution or there was an error with the command itself. */
  177. /* In the former case, rc2 contains the error message and in */
  178. /* the latter, rc2 contains an error number. SIGL contains */
  179. /* the line number of the command which caused the jump */
  180. /* to ERROR: */
  181.  
  182. if datatype(rc2,'NUMERIC') == 1 then do
  183.    /* See if we can describe the error with a string */
  184.  
  185.    select
  186.       when rc2 == 103 then
  187.          err_string = "ERROR 103, "||,
  188.             "out of memory at line "||SIGL
  189.       when rc2 == 114 then
  190.          err_string = "ERROR 114, "||,
  191.             "bad command template at line "||SIGL
  192.       when rc2 == 115 then
  193.          err_string = "ERROR 115, "||,
  194.             "bad number for /N argument at line "||SIGL
  195.       when rc2 == 116 then
  196.          err_string = "ERROR 116, "||,
  197.             "required argument missing at line "||SIGL
  198.       when rc2 == 117 then
  199.          err_string = "ERROR 117, "||,
  200.             "value after keywork missing at line "||SIGL
  201.       when rc2 == 118 then
  202.          err_string = "ERROR 118, "||,
  203.             "wrong number of arguments at line "||SIGL
  204.       when rc2 == 119 then
  205.          err_string = "ERROR 119, "||,
  206.             "unmatched quotes at line "||SIGL
  207.       when rc2 == 120 then
  208.          err_string = "ERROR 120, "||,
  209.             "line too long at line "||SIGL
  210.       when rc2 == 236 then
  211.          err_string = "ERROR 236, "||,
  212.             "unknown command at line "||SIGL
  213.       otherwise
  214.          err_string = "ERROR "||rc2||", at line "||SIGL
  215.       end
  216.         end
  217. else if rc2 == 'RC2' then do
  218.    err_string = "ERROR in command at line "||SIGL
  219.    end
  220. else do
  221.         err_string = rc2||", line "||SIGL
  222.         end
  223.  
  224. request_message TEXT '"'err_string'"'
  225.  
  226. exit
  227.  
  228.